import request from 'umi-request';

export async function getTransferInfoList(params,type,dealStatus) {
  return request('/hr-ssc/api/api-admin/transfer/getTransferInfoList', {
    method: 'post',
    data: {
      pageNum: params.current,
      type: type,
      dealStatus: dealStatus,
      ...params
    },
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getJobByOrgId(id) {
  return request(`/hr-ssc/api/api-admin/job/findJobByOrgId/${id}`, {
    method: 'get'
  }).then((res) => {
    return res.data;
  });
}

export async function saveTransfer(params) {
  return request(`/hr-ssc/api/api-admin/transfer/saveTransfer`, {
    method: 'post',
    data: {
      ...params
    },
  }).then((res) => {
    return res;
  });
}

export async function deleteTransfer(transferId) {
  return request(`/hr-ssc/api/api-admin/transfer/deleteTransferInf?transferId=`+transferId, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function updateTransfer(params) {
  let {transferId, afterJobLevelType, ...datas} = params;
  return request(`/hr-ssc/api/api-admin/transfer/updateTransfer`, {
    method: 'post',
    data: {
      ...datas,
      afterJobLevelType: parseInt(afterJobLevelType),
      transferId: parseInt(transferId)
    },
  }).then((res) => {
    return res;
  });
}

export async function findEmpByCode(userCode) {
  return request(`/hr-ssc/api/api-admin/transfer/findEmpByCode?userCode=`+userCode, {
    method: 'get',
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return {};
    }
  });
}

export async function auditTransfer(transferId) {
  return request(`/hr-ssc/api/api-admin/bpm/transferEmp`, {
    method: 'post',
    data: {
      transferId: transferId
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function confirmEntryInterface(transferId,hireDate) {
  return request(`/hr-ssc/api/api-admin/transfer/updateHireStatus`, {
    method: 'post',
    data: {
      transferId: transferId,
      hireDate: hireDate
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function updateAuditStatus(transferId) {
  return request(`/hr-ssc/api/api-admin/transfer/updateAuditStatus`, {
    method: 'post',
    data: {
      id: transferId
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function findTiaoxinTixiByJobId(jobId) {
  return request(`/hr-ssc/api/api-admin/job/findTiaoxinTixiByJobId/${jobId}`, {
    method: 'get',
  }).then((res) => {
    return res;
  });
}

export async function getPersonRecord(oid) {
  return request(`/hr-ssc/api/api-admin/contract/getPersonRecord`, {
    method: 'post',
    data: {oid},
    requestType: 'form'
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return null;
  });
}

export async function getComputerSubsidyByOid(oid) {
  return request(`/hr-ssc/api/api-admin/secondment/getComputerSubsidyByOid`, {
    method: 'post',
    data: {oid},
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}
